package com.oscarmovie.model;

import java.util.HashSet;
import java.util.Set;

public class Mpr {
	private int id;
	private Movie movie;
	private Person person;
	private Role role;

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public void setMovie(Movie movie) {
		this.movie = movie;
	}

	public Movie getMovie() {
		return movie;
	}

	public void setPerson(Person person) {
		this.person = person;
	}

	public Person getPerson() {
		return person;
	}

	public void setRole(Role role) {
		this.role = role;
	}

	public Role getRole() {
		return role;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((movie == null) ? 0 : movie.hashCode());
		result = prime * result + ((person == null) ? 0 : person.hashCode());
		result = prime * result + ((role == null) ? 0 : role.hashCode());
		return result;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object present) {
		if (this == present)
			return true;

		if (present == null)
			return false;

		if (getClass() != present.getClass())
			return false;

		Mpr presentMpr = (Mpr) present;

		if (movie == null) {
			if (presentMpr.movie != null)
				return false;
		} else if (!movie.equals(presentMpr.movie)) {
			return false;
		}

		if (person == null) {
			if (presentMpr.person != null)
				return false;
		} else if (!person.equals(presentMpr.person)) {
			return false;
		}

		if (role == null) {
			if (presentMpr.role != null)
				return false;
		} else if (!role.equals(presentMpr.role)) {
			return false;
		}
		return true;
	}
	
public static void main(String[] args) {
	Movie m = new Movie();
	m.setId(1);
	
	Person p = new Person();
	p.setId(2);
	
	Role r = new Role();
	r.setId(3);
	
	Mpr mpr=new Mpr();
	mpr.setMovie(m);
	mpr.setPerson(p);
	mpr.setRole(r);
	
	
	Movie m2 = new Movie();
	m2.setId(1);
	
	Person p2 = new Person();
	p2.setId(2);
	
	Role r2 = new Role();
	r2.setId(3);
	
	Mpr mpr2=new Mpr();
	mpr2.setMovie(m2);
	mpr2.setPerson(p2);
	mpr2.setRole(r2);
	
	Set<Mpr> mprs = new HashSet<Mpr>();
	mprs.add(mpr);
	mprs.add(mpr2);
	System.out.println(mprs.size());
}
	// public int hashCode() {
	// int code = movie.getId() * 100000 + person.getId() * 1000 + movie.getId();
	// return code;
	// }

//	 public boolean equals(Object object) {
//		 boolean t = false;
//		 if (object != null) {
//		 Mpr mpr = (Mpr) object;
//		 t = mpr.getPerson().getId() == person.getId() && mpr.getRole().getId() == role.getId()
//		 && mpr.getMovie().getId() == movie.getId();
//		 }
//		 return t;
//	 }

}
